﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AfvandingService.DOAs
{
    internal class PumpestationDOA : IPumpestationDAO
    {
        private string CONNECTIONSTRING = ConfigurationManager.ConnectionStrings["Afvandingsprojekt"].ConnectionString;

        public void OpretPumpe(Pumpe pumpe)
        {
            using (SqlConnection conn = new SqlConnection(CONNECTIONSTRING))
            {
                SqlCommand cmd = new SqlCommand("SP_OpretPumpe", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                conn.Open();

                cmd.Parameters.AddWithValue("@Pumpekapacitet", pumpe.Pumpekapacitet);
                cmd.Parameters.AddWithValue("@Pumpenr", pumpe.Pumpenr);
                cmd.Parameters.AddWithValue("@PumpestationsNr", pumpe.PumpestationsNr);
                cmd.Parameters.AddWithValue("@Pumpestatus", pumpe.Status);

                cmd.ExecuteNonQuery();
            }
        }

        public void OpdatérPumpe(Pumpe pumpe)
        {
            using (SqlConnection conn = new SqlConnection(CONNECTIONSTRING))
            {
                SqlCommand cmd = new SqlCommand("SP_OpdatérPumpe", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                conn.Open();

                cmd.Parameters.AddWithValue("@Pumpekapacitet", pumpe.Pumpekapacitet);
                cmd.Parameters.AddWithValue("@Pumpenr", pumpe.Pumpenr);
                cmd.Parameters.AddWithValue("@PumpestationsNr", pumpe.PumpestationsNr);
                cmd.Parameters.AddWithValue("@Pumpestatus", pumpe.Status);

                cmd.ExecuteNonQuery();
            }
        }

        public void SletPumpe(int pumpestationsnr, int pumpenr)
        {
            using (SqlConnection conn = new SqlConnection(CONNECTIONSTRING))
            {
                SqlCommand cmd = new SqlCommand("SP_SletPumpe", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                conn.Open();

                cmd.Parameters.AddWithValue("@Pumpenr", pumpenr);
                cmd.Parameters.AddWithValue("@PumpestationsNr", pumpestationsnr);
                cmd.ExecuteNonQuery();
            }
        }

        public void ÆndrPumpeStatus(int pumpestationsnr, int pumpenr, bool status)
        {
            using (SqlConnection conn = new SqlConnection(CONNECTIONSTRING))
            {
                SqlCommand cmd = new SqlCommand("SP_StartogStopPumpe", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                conn.Open();

                cmd.Parameters.AddWithValue("@Pumpenr", pumpenr);
                cmd.Parameters.AddWithValue("@PumpestationsNr", pumpestationsnr);
                cmd.Parameters.AddWithValue("@Status", status);
                cmd.ExecuteNonQuery();
            }
        }
    }
}
